package com.anywhere.freightman.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisClient {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /*@Value("${spring.redis.host}")
    private String redisHost;

    private Jedis jedis = null;

    private Jedis getJedis() {
        if (jedis == null) {
            jedis = new Jedis(redisHost);
        }
        return jedis;
    }*/

    public String getString(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    public void setValue(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value, 2, TimeUnit.HOURS);
    }

    public void remove(String key) {
        stringRedisTemplate.delete(key);
    }

}
